
package tools;



import java.io.ByteArrayOutputStream;










 public class HexTool
         {
    /*  15 */   private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};










    public static String toString(byte byteValue) {
        /*  25 */
        int tmp = byteValue << 8;
        /*  26 */
        char[] retstr = {HEX[tmp >> 12 & 0xF], HEX[tmp >> 8 & 0xF]};
        /*  27 */
        return String.valueOf(retstr);

    }































    public static String toString(int intValue) {
        /*  59 */
        return Integer.toHexString(intValue);

    }










    public static String toString(byte[] bytes) {
        /*  70 */
        if (bytes == null || bytes.length < 1) {
            /*  71 */
            return "";

        }
        /*  73 */
        StringBuilder hexed = new StringBuilder();
        /*  74 */
        for (byte aByte : bytes) {
            /*  75 */
            hexed.append(toString(aByte));
            /*  76 */
            hexed.append(' ');

        }
        /*  78 */
        return hexed.substring(0, hexed.length() - 1);

    }












    public static String toStringFromAscii(byte[] bytes) {
        /*  91 */
        byte[] ret = new byte[bytes.length];
        /*  92 */
        for (int x = 0; x < bytes.length; x++) {
            /*  93 */
            if (bytes[x] < 32 && bytes[x] >= 0) {
                /*  94 */
                ret[x] = 46;

            } else {
                /*  96 */
                ret[x] = bytes[x];

            }

        }
        /*  99 */
        String encode = "gbk";

        try {
            /* 101 */
            return new String(ret, encode);
            /* 102 */
        } catch (Exception exception) {

            /* 104 */
            return "";

        }

    }


    public static String toPaddedStringFromAscii(byte[] bytes) {
        /* 108 */
        String str = toStringFromAscii(bytes);
        /* 109 */
        StringBuilder ret = new StringBuilder(str.length() * 3);
        /* 110 */
        for (int i = 0; i < str.length(); i++) {
            /* 111 */
            ret.append(str.charAt(i));
            /* 112 */
            ret.append("  ");

        }
        /* 114 */
        return ret.toString();

    }










    public static byte[] getByteArrayFromHexString(String hex) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int nexti = 0;
        int nextb = 0;
        boolean highoc = true;
        outer:
        for (; ; ) {
            int number = -1;
            while (number == -1) {
                if (nexti == hex.length()) {
                    break outer;
                }
                char chr = hex.charAt(nexti);
                if (chr >= '0' && chr <= '9') {
                    number = chr - '0';
                } else if (chr >= 'a' && chr <= 'f') {
                    number = chr - 'a' + 10;
                } else if (chr >= 'A' && chr <= 'F') {
                    number = chr - 'A' + 10;
                } else {
                    number = -1;
                }
                nexti++;
            }
            if (highoc) {
                nextb = number << 4;
                highoc = false;
            } else {
                nextb |= number;
                highoc = true;
                baos.write(nextb);
            }
        }
        return baos.toByteArray();
    }



    public static String getOpcodeToString(int op) {
        /* 161 */
        return "0x" + StringUtil.getLeftPaddedStr(Integer.toHexString(op).toUpperCase(), '0', 4);

    }



    public static String getBuffStatToString(int buffstat) {
        /* 165 */
        String ret = "0x";
        /* 166 */
        ret = ret + StringUtil.getLeftPaddedStr(Integer.toHexString(buffstat).toUpperCase(), '0', 1);
        /* 167 */
        return ret;

    }






    public static String getSubstring(String pStr, int pStart, int pEnd) {
        byte[] b = pStr.getBytes();
        pStr = "";
        for (int i = pStart - 1, point = pStart - 1; i < pEnd; ) {
            if (i >= b.length) {
                break;
            }
            if (i == pEnd - 1 && b[i] < 0) {
                int length = i - point + 1;
                if (length % 2 == 1) {
                    length--;
                }
                pStr += new String(b, point, length);
            }
            i++;
            if (b[i] >= 0) {
                pStr += new String(b, point, i - point);
                point = i;
            }
        }
        return pStr;
    }

}


/* Location:              C:\PGX\Server.jar!\tools\HexTool.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */